<template>
  <div class="products-view">
    <div class="container">
      <h1 class="page-title">PRODUCTS SHOWCASE</h1>
      
      <!-- 产品网格 -->
      <div class="products-grid" v-if="!loading">
        <div 
          v-for="product in products"
          :key="product.id"
          class="product-card"
          @click="goToProductDetail(product.id)"
        >
          <div class="product-image">
            <img 
              v-if="getProductMainImage(product)"
              :src="getProductMainImage(product)" 
              :alt="product.name_en"
            />
            <div v-else class="no-image">No Image</div>
          </div>
          <div class="product-name">{{ product.name_en }}</div>
        </div>
        
        <!-- 右侧特色标签 -->
        <div class="feature-tags">
          <div class="feature-tag">
            <span class="tag-icon">✓</span>
            <span class="tag-text">Primary Processed Fish</span>
          </div>
          <div class="feature-tag">
            <span class="tag-icon">✓</span>
            <span class="tag-text">Intermediate Processed Fish</span>
          </div>
          <div class="feature-tag">
            <span class="tag-icon">✓</span>
            <span class="tag-text">Pre-made Food</span>
          </div>
          <div class="feature-tag">
            <span class="tag-icon">✓</span>
            <span class="tag-text">OEM & ODM</span>
          </div>
        </div>
      </div>

      <!-- 加载状态 -->
      <div v-if="loading" class="loading">
        <p>Loading...</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useProductsStore } from '../stores/products'

const router = useRouter()
const productsStore = useProductsStore()

const loading = computed(() => productsStore.loading)
const products = computed(() => {
  return productsStore.getActiveProducts().sort((a, b) => a.order - b.order)
})

const getProductMainImage = (product: any) => {
  return productsStore.getProductMainImage(product)
}

const goToProductDetail = (productId: number) => {
  router.push({ name: 'productDetail', params: { id: productId } })
}

onMounted(async () => {
  await productsStore.fetchSettings()
})
</script>

<style scoped>
.products-view {
  min-height: 100vh;
  background: #ffffff;
  padding: 40px 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-title {
  font-size: 18px;
  font-weight: normal;
  text-align: center;
  margin-bottom: 40px;
  color: #333;
  letter-spacing: 2px;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  position: relative;
}

.product-card {
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.product-card:hover {
  opacity: 0.8;
}

.product-image {
  width: 100%;
  height: 250px;
  background: #f5f5f5;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.no-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 14px;
}

.product-name {
  margin-top: 10px;
  font-size: 14px;
  text-align: center;
  color: #333;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 右侧特色标签 */
.feature-tags {
  position: absolute;
  right: -200px;
  top: 0;
  width: 180px;
}

.feature-tag {
  background: #6ca55f;
  color: white;
  padding: 12px 15px;
  margin-bottom: 10px;
  border-radius: 25px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  white-space: nowrap;
}

.tag-icon {
  background: white;
  color: #6ca55f;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
}

.tag-text {
  line-height: 1.2;
}

.loading {
  text-align: center;
  padding: 60px 0;
  color: #666;
}

/* 响应式设计 */
@media (max-width: 1400px) {
  .feature-tags {
    position: static;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 30px;
  }
  
  .feature-tag {
    flex: 0 0 auto;
  }
}

@media (max-width: 992px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }
  
  .product-image {
    height: 200px;
  }
  
  .feature-tags {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .products-grid {
    grid-template-columns: 1fr;
  }
  
  .product-image {
    height: 250px;
  }
}
</style>